<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span @click="$emit('update-histories', [])">全部删除</span>
        <span @click="isDeleteShow = false" >完成</span>
      </div>
      <van-icon v-else
       name="delete"
       @click="isDeleteShow = true" />
    </van-cell>
    <van-cell
     :title="searchHistory"
     v-for="(searchHistory,index) in searchHistories"
     :key="index"
     @click="onDelete(searchHistory, index)"
     >
      <van-icon name="close" v-show="isDeleteShow" />
    </van-cell>
  </div>
</template>

<script>
// import { setItem } from '@/utils/storage'
export default {
  name: 'SearchHistory',
  components: {},
  props: {
    searchHistories: {
      type: Array,
      require: true
    }
  },
  data () {
    return {
      isDeleteShow: false
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    onDelete (searchHistory, index) {
      if (this.isDeleteShow) {
        this.searchHistories.splice(index, 1)
        // setItem('search-histories', this.searchHistories)
        return
      }
      this.$emit('search', searchHistory)
    }
  }
}
</script>

<style scoped lang="less"></style>
